﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WaveMaster.Holidays.Club.Gateway;
using WaveMaster.Holidays.Club.Domain;
using MySql.Data.MySqlClient;
using WaveMaster.Holidays.Club.SQL;

namespace WaveMaster.Holidays.Club.Service
{
    public class ConfigurationService : IService
    {
        DataBaseConnectivity m_dataBaseConectivity;
        public ConfigurationService(DataBaseConnectivity dataBaseConectivity)
        {
            m_dataBaseConectivity = dataBaseConectivity;
        }
        public ConfigurationService()
        {
            m_dataBaseConectivity = new DataBaseConnectivity();
        }
        public Configuration GetConfigurationByName(string name)
        {
            Configuration user = null;
            try
            {
                m_dataBaseConectivity.InterfaceSqlConnection.Open();
                MySqlCommand cmd = new MySqlCommand(ConfigurationSQL.GetConfigurationtByName(), m_dataBaseConectivity.InterfaceSqlConnection);
                cmd.Parameters.Add("config_name", MySqlDbType.VarChar).Value = name;
                //LogService.WriteLogExecuteSQLCommand(cmd);
                MySqlDataReader rd = cmd.ExecuteReader();
                while (rd.Read())
                {
                    user = new Configuration(rd);
                }
            }
            catch (Exception x)
            {
                LogService.WriteLogException(x);
                throw x;
            }
            finally
            {
                m_dataBaseConectivity.InterfaceSqlConnection.Close();
            }
            return user;
        }
    }
}
